/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shaman.storage;

import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Shaman
 */
public class TableModelRules extends AbstractTableModel {

    private BackupTask m_task;
    
    public TableModelRules(BackupTask task)
    {
        m_task = task;
    }

    public int getRowCount() {
        return m_task.getRules().size();
    }

    public int getColumnCount() {
        return 4;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex)
    {
        if (columnIndex == 0)
            return Boolean.class;
        else
            return String.class;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Rule curRule = null;
        try
        {
           curRule =  m_task.getRules().get(rowIndex);
        }
        catch (IndexOutOfBoundsException exc)
        {
            return null;
        }
        switch (columnIndex)
        {
            case 0: return curRule.isAddable();
            case 1: return curRule.getRuleTypeName();
            case 2: return curRule.getDirectory();
            case 3: return curRule.getValue();
        }
        return null;
    }

    @Override
    public String getColumnName(int col) {
        switch (col)
        {
            case 0: return "Добавляющее правило";
            case 1: return "Тип правила";
            case 2: return "Папка";
            case 3: return "Текст правила";
        }
        return "NONE";
    }

    @Override
    public boolean isCellEditable(int row, int col) {
        return false;
    }
}
